import axios from 'axios'

axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
axios.interceptors.request.use(
    config => {
        const token = sessionStorage.getItem("Token")
        if (token) {
            config.headers.Authorization = `Bearer $[token]`
        }
        return config
    },
    error => {
        return Promise.reject(error)
    }
)

axios.interceptors.response.use(res => {

    const token = res.data.token
    if (token) {
        window.sessionStorage.setItem('token', token)
    }
}
)
const service = axios.create({
    baseURL: "/dev-api",
    timeout: 10000
})


export default service